package com.nisco.dms.entity;

import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;

import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;

import com.google.common.base.Objects;
import com.google.common.collect.Lists;

@Entity
@Table(name = "Do_Department")
@Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE, region = "com.nisco.dms.entity")
public class Department extends CoreEntity {
	@Column
	private String strName; 
	
	@Column
	private String strSn;
	
	@Column
	private String strDesc;
	@Column(name = "fatherId",insertable=false,updatable=false)
	private String fatherId;
	
	@ManyToOne
	@JoinColumn(name = "fatherId")
	private Department parent;

	@OneToMany(cascade = CascadeType.PERSIST, mappedBy = "parent")
	private List<Department> children = Lists.newArrayList();

	@OneToMany(cascade = CascadeType.PERSIST, mappedBy = "dept" )
	private List<User> users = Lists.newArrayList();

	
	public String getStrName()
	{
		return strName;
	}


	public void setStrName(String strName)
	{
		this.strName = strName;
	}



	public String getStrSn()
	{
		return strSn;
	}


	public void setStrSn(String strSn)
	{
		this.strSn = strSn;
	}


	public String getStrDesc()
	{
		return strDesc;
	}


	public void setStrDesc(String strDesc)
	{
		this.strDesc = strDesc;
	}

	

	
	public String getFatherId()
	{
		return fatherId;
	}


	public void setFatherId(String fatherId)
	{
		this.fatherId = fatherId;
	}


	public Department getParent()
	{
		return parent;
	}


	public void setParent(Department parent)
	{
		this.parent = parent;
	}


	public List<Department> getChildren()
	{
		return children;
	}


	public void setChildren(List<Department> children)
	{
		this.children = children;
	}


	public List<User> getUsers()
	{
		return users;
	}


	public void setUsers(List<User> users)
	{
		this.users = users;
	}


	@Override
	public String toString() {
		return Objects.toStringHelper(this).addValue(id).addValue(strName).addValue(parent == null ? null : parent.getStrName()).addValue(children.size()).toString();
	}
}
